import axios from 'axios';

export interface MyProjectRecord {
    id: number;
    name: string;
    description: string;
    peopleNumber: number;
    contributors: {
        name: string;
        email: string;
        avatar: string;
    }[];
}

export function queryMyProjectList() {
    return axios.post('/api/user/my-project/list');
}


export function queryMyTeamList() {
    return axios.post('/api/user/my-team/list');
}

export interface LatestActivity {
    id: number;
    title: string;
    description: string;
    avatar: string;
}

export function queryLatestActivity() {
    return axios.post<LatestActivity[]>('/api/user/latest-activity');
}

export function saveUserInfo() {
    return axios.post('/api/user/save-info');
}

export interface BasicInfoModel {
    email: string;
    nickname: string;
    countryRegion: string;
    area: string;
    address: string;
    profile: string;
}


export function fileUpdate(
    data: FormData,
    config: {
        controller: AbortController;
        onUploadProgress?: (progressEvent: any) => void;
    }
) {
    return axios.post('/participant/close/admin/upload-avatar', data, config);
}


export interface UpdatePassword {
    oldPassword: string,
    reOldPassword: string,
    newPassword: string
}

export function generateUpdatePassword(_oldPassword: string, _reOldPassword: string, _newPassword: string): UpdatePassword {
    const updatePwd: UpdatePassword = {
        oldPassword: _oldPassword,
        reOldPassword: _reOldPassword,
        newPassword: _newPassword
    };
    return updatePwd;
}

export function updatePassword(params:  UpdatePassword ) {
    return axios.get('/participant/close/admin/update-password', {params});
}


export interface MyTeamRecord {
    number: string;
    avatarUrl: string;
    username: string;
    roleName: string;
}

export function showTeam() {
    return axios.get<MyTeamRecord>('/participant/close/admin/show-team');
}

export interface MyTeamDynamic {
    context: string;
    avatarUrl: string;
    username: string;
    roleName: string;
}

export function showDynamic() {
    return axios.get<MyTeamDynamic>('/participant/close/admin/show-dynamic');
}


